/*************************************************************************/
/** Copyright.															**/
/** FileName: UserAction.c												**/
/** Author: XuYulin														**/
/** Version: 1.0.0.0													**/
/** Description: User operation interface.								**/
/** History:															**/
/**	XuyYulin	2017/2/27	2.0.0.0		New create.						**/
/** XuYulin 2017/2/27 1.0 build this moudle								**/
/*************************************************************************/

//=======================================================================//
//= Include files.													    =//
//=======================================================================//
#include "UserAction.h"
#include "LCD_OperationIF.h"

#include "GUI_Basic.h"
#include "GUI_Font.h"
#include "GUI_VariableBox.h"

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

//=======================================================================//
//= Static variable declaration.									    =//
//=======================================================================//
RECTANGLE				stTextDisplayArea = {10, 40, 108, 14};
RECTANGLE				stTextDataArea = {0, 0};
char					szTextVarBuffer[21] = {"123456"};
GUI_TXT_VARBOX_STRUCT	stTextVar = {10, 10, 50, 0, 20, szTextVarBuffer};

//=======================================================================//
//= Static function declaration.									    =//
//=======================================================================//

//=======================================================================//
//= Function implementation.										    =//
//=======================================================================//
/*************************************************************************/
/** Function Name:	USR_ACT_OnInitialize								**/
/** Purpose:		Process with application startup.					**/
/** Resources:		None.												**/
/** Params:			None.												**/
/** Return:			None.												**/
/** Notice:			None.												**/
/*************************************************************************/
void USR_ACT_OnInitialize(void)
{
	GUI_Basic_DrawRectangle(9, 9, 52, 16, GUI_COLOR_FRGCLR, GUI_COLOR_TRANS);
	GUI_Basic_DrawRectangle(9, 39, 110, 16, GUI_COLOR_FRGCLR, GUI_COLOR_TRANS);
	GUI_TextVariableBox_Refresh(&stTextVar, GUI_DRAW_NORMAL);
}

/*************************************************************************/
/** Function Name:	USR_ACT_OnKeyPress									**/
/** Purpose:		Recive and process keyboard event.					**/
/** Resources:		None.												**/
/** Params:																**/
/** @uiKeyCode:			Key code.										**/
/** Return:			None.												**/
/** Notice:			None.												**/
/*************************************************************************/
void USR_ACT_OnKeyPress(uint16_t uiKeyCode)
{
	switch(uiKeyCode)
	{
		case KEY_VALUE_SPACE:
		{
			break;
		}
		case KEY_VALUE_ENTER:
		{
			GUI_Text_DrawSingleLineText(stTextVar.Value, FONT_SIZE_H12, &stTextDisplayArea, &stTextDataArea, GUI_DRAW_NORMAL);
			break;
		}
		case KEY_VALUE_ESC:
		{
			break;
		}
		case KEY_VALUE_UP:
		{
			GUI_TextVariableBox_ChangeCharacter(&stTextVar, GUI_DRAW_NORMAL, GUI_TEXT_ASCII, GUI_TXT_VARBOX_OPT_PREV);
			break;
		}
		case KEY_VALUE_DOWN:
		{
			GUI_TextVariableBox_ChangeCharacter(&stTextVar, GUI_DRAW_NORMAL, GUI_TEXT_ASCII, GUI_TXT_VARBOX_OPT_NEXT);
			break;
		}
		case KEY_VALUE_RIGHT:
		{
			if(stTextVar.FocusIndex < stTextVar.MaxTextLength)
			{
				stTextVar.FocusIndex++;
				GUI_TextVariableBox_Refresh(&stTextVar, GUI_DRAW_NORMAL);
			}
			break;
		}
		case KEY_VALUE_LEFT:
		{
			if(stTextVar.FocusIndex > 0)
			{
			stTextVar.FocusIndex--;
			GUI_TextVariableBox_Refresh(&stTextVar, GUI_DRAW_NORMAL);
			}
			break;
		}
		default:
		{
			break;
		}
	}
}

